try {

var FFMCcontacts;
var FFMCsortednames;

function FFMCLoad() {
	var nocontacts = JSON.stringify({"names":[],"lownames":[],"notes":[]});
	var contactsText = localStorage.getItem("FFMContactsOrion");
	//return nocontacts;
	if (!contactsText) {
		return nocontacts;
	}
	else {
		return contactsText;
	}
}

function FFMCSave() {
	localStorage.setItem("FFMContactsOrion", JSON.stringify(FFMCcontacts));
}

function FFMClastLoad() {
	if (!sessionStorage.FFMClastLoad) {
		return 0;
	} else {
		return sessionStorage.FFMClastLoad;
	}
}

function FFMCdataGMmod() {
	var now = (new Date).getTime();
	if ((now - parseInt(FFMClastLoad())) > 120000) {
		var request = new XMLHttpRequest();
		request.onreadystatechange = function () {
			if (request.readyState == 4 && request.status == 200) {
				sessionStorage.FFMClastLoad = now.toString();
				FFMCparsedataGMmod(true,request.responseText);
			} else {
			}
		};
	    request.open("GET", "http://" + location.hostname + "/statistics.php?display=onlinelist", true);
	    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send(null);		
	} else {
		FFMCparsedataGMmod(false,"");
	}
}

function FFMCparsedataGMmod(freshload,text) {
	
	var online = {"names":[]};
	
	if (freshload === true) {
		var box = document.createElement("div");
		box.innerHTML = text;
		
		var links = box.getElementsByClassName('messagestyle')[1].getElementsByTagName('a');
		for (var i = 0;i < links.length;i++) {
			online.names.push(links[i].innerHTML.toLowerCase());
		}
		box = null;
		sessionStorage.FFMConlineOrion = JSON.stringify(online);
	} else {
		if (!sessionStorage.FFMConlineOrion) {
			online = {"names":[]};
		} else {
			online = JSON.parse(sessionStorage.FFMConlineOrion);
		}
	}
	
	var imgsrc = document.images[0].src;
	var active = imgsrc.replace("text1.png","dipl_ally_active.png");
	var inactive = imgsrc.replace("text1.png","dipl_ally_inactive.png");
	
	var loaders = document.getElementsByClassName('loading1');
	for (var i = 0;i < FFMCcontacts.names.length;i++) {
		if (online.names.indexOf(FFMCsortednames[i].toLowerCase()) !== -1) {
			loaders[i].src = active;
		} else {
			loaders[i].src = inactive;
		}
	}
}

function FFMCinstall() {

	FFMCcontacts = JSON.parse(FFMCLoad());
	var td = document.getElementsByTagName('h3')[1].parentNode;
	var html = "<br><h3 style='color: orange;'>Contacts</h3><table cellspacing='0' cellpadding='0'><tbody>";
	FFMCsortednames = FFMCcontacts.names.join(";");
	FFMCsortednames = FFMCsortednames.split(";");
	FFMCsortednames.sort();

	var index = 0;
	for (var i = 0;i < FFMCcontacts.names.length;i++) {
		index = FFMCcontacts.names.indexOf(FFMCsortednames[i]);
		html += "<tr><td width='14' style='vertical-align: middle; width: 14px; text-align: left;'><img class='loading1' src=''></td><td width='14'></td><td style='vertical-align: middle; text-align: left;'><a title='" + FFMCcontacts.notes[index] + "' href='javascript:sendmsg(\"" + FFMCcontacts.names[index] + "\")'>" + FFMCcontacts.names[index] + "</a></td></tr>";
	}
	td.innerHTML = html + "</tbody></table>" + td.innerHTML;

	FFMCdataGMmod();
}

FFMCinstall();

}
catch(err) {
	alert("Error:\n" + err.message);
}